package com.gosun;

import java.io.*;

public class getResult {
    public static void getData( String data, String path) {
        try {

            File path1 = new File(path);
            String dirpath = path1.getParent();
            File dir = new File(dirpath);
            //String name = path1.getName();
            //File file = new File(name);


            //创建目录
            if (!dir.isDirectory()) {
                dir.mkdirs();
                System.out.println("创建目录成功！");
            }
            //创建文件
            if (!path1.exists()) {
                path1.createNewFile();
                System.out.println("文件创建成功！");
            }
            FileOutputStream outputStream = new FileOutputStream(path1, true);
            OutputStreamWriter os = new OutputStreamWriter(outputStream);
            BufferedWriter bufferedWriter = new BufferedWriter(os,8192);

            bufferedWriter.write(data);
            bufferedWriter.flush();
            System.out.println("写入成功！");
            bufferedWriter.close();
            os.close();
            outputStream.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
